package input;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import map.Map;

public class KeyboardInput implements AbstractInput, KeyListener {
	public direction actualDir = direction.stop;
	public boolean shoot = false;
	private boolean _state = false;
	Map map;

	public void setMap(Map map) {
		this.map = map;
	}

	@Override
	public void keyPressed(KeyEvent e) {
		if (e.getKeyCode() == 68)
			actualDir = direction.right;
		if (e.getKeyCode() == 65)
			actualDir = direction.left;
		if (e.getKeyCode() == 83)
			actualDir = direction.down;
		if (e.getKeyCode() == 87)
			actualDir = direction.up;
		if ((e.getKeyCode() == 32)&&(!_state)) {
			shoot = true;
			_state = true;
		}
	}

	@Override
	public void keyReleased(KeyEvent e) {
		if ((e.getKeyCode() == 68) || (e.getKeyCode() == 65)
				|| (e.getKeyCode() == 83) || (e.getKeyCode() == 87))
			actualDir = direction.stop;
		if (e.getKeyCode() == 32) {
			shoot = false;
			_state = false;
		}
	}

	@Override
	public void keyTyped(KeyEvent e) {
	}

	@Override
	public direction getDir() {
		return actualDir;
	}

	@Override
	public void setDir(direction dir) {
		actualDir = dir;
	}

	@Override
	public boolean isShoot() {
		boolean temp = shoot;
		shoot = false;
		return temp;
	}
}
